package demo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-06-20
 * Time: 21:42
 */

class Solution {
    public int[] sortedSquares(int[] nums) {
        int left = 0;
        int right = nums.length-1;
        int index =nums.length-1;
        int[] tmp = new int[nums.length];
        while(left<=right){
            if(nums[left]*nums[left]<nums[right]*nums[right]){
                tmp[index--] = nums[right]*nums[right];
                right--;
            }else {
                tmp[index--] = nums[left]*nums[left];
                left++;
            }
        }
        return nums;
    }
}
public class TestDemo2 {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {-4,-1,0,3,10};
        solution.sortedSquares(nums);
    }
}
